﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wyn.PMS.Common.NightAudit;
using Wyn.PMS.Logic.Business;

namespace Wyn.PMS.Test.Cache
{
    internal class RoomCountCacheTest
    {
        public static void Test(string hotelId)
        {
            RoomCountCache rcc = RoomCountCache.GetInstance();

            var counts = rcc.GetHotelRoomCount(hotelId, DateTime.Today.AddDays(-1), DateTime.Today.AddDays(10));

            int uc = 4, oc = 8, oo = 6, ac = 4;

            foreach (var item in counts)
            {
                Console.WriteLine(item.Key);

                Console.Write("★ 可用数 | 订单占房数 | 总占房数 | 总房量 | 房型 \n\r");
                
                foreach (var count in item.Value)
                {
                    string fmstr = "     "+count.UsableCount.ToString().PadRight(uc, ' ');

                    fmstr += " |   "+ count.OrderCount.ToString().PadRight(oc, ' ');

                    fmstr += " |   "+ count.OccupyCount.ToString().PadRight(oo, ' ');

                    fmstr += " |   "+ count.Count.ToString().PadRight(ac, ' ');

                    fmstr += " | " + string.Format("{0}({1})\n\r", count.RoomTypeID, count.RoomTypeName);

                    Console.Write(fmstr);
                }
            }

            Console.Write("★ ------------------------------------------ \n\r");

            Console.Write("★ 酒店指定时间段可用房量查看 \n\r");

            bool isContinue = true;

            DateTime startDate=DateTime.Today, endDate=DateTime.Today.AddDays(1);

            while (isContinue)
            {
                Console.Write("\r\n 请输入日期段,格式 2012-10-1,2012-10-7 ：");

                string arg = Console.ReadLine();

                var args = arg.Split(',');

                if (!DateTime.TryParse(args[0], out startDate) || !DateTime.TryParse(args[1], out endDate))
                {
                    continue;
                }
               

                if (endDate<startDate)
                {
                    Console.WriteLine("开始日期不能大于结束日期");
                    continue;
                }

                isContinue = false;
            }


            Console.Write("★ 可用数 | 订单占房数 | 总占房数 | 总房量 | 房型 \n\r");

            var usableCount = rcc.GetUsableRoomCount(hotelId, startDate,endDate);

            foreach (var count in usableCount)
            {
                string fmstr = "     " + count.UsableCount.ToString().PadRight(uc, ' ');

                fmstr += " |   " + count.OrderCount.ToString().PadRight(oc, ' ');

                fmstr += " |   " + count.OccupyCount.ToString().PadRight(oo, ' ');

                fmstr += " |   " + count.Count.ToString().PadRight(ac, ' ');

                fmstr += " | " + string.Format("{0}({1})\n\r", count.RoomTypeID, count.RoomTypeName);

                Console.Write(fmstr);
            }
            
        }

        
    }
}
